package com.seqb.utils;

import org.apache.commons.lang3.StringUtils;

import javax.servlet.http.HttpServletRequest;

/**
 * @author lilinshen
 * @title Servlet工具类
 * @description 请填写相关描述
 * @date 2019/11/11
 */
public class HttpServletUtils {
    private static final String X_REQUEST_WITH = "x-requested-with";
    private static final String XML_HTTP_REQUEST = "XMLHttpRequest";

    /**
     * 判断是否为ajax请求，默认不是
     */
    public static boolean jsAjax(HttpServletRequest req) {
        boolean isAjaxRequest = false;
        if (!StringUtils.isBlank(req.getHeader(X_REQUEST_WITH)) && XML_HTTP_REQUEST.equals(req.getHeader(X_REQUEST_WITH))) {
            isAjaxRequest = true;
        }
        return isAjaxRequest;
    }
}
